﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Communication.Base;

namespace UtilZ.Dotnet.Ex.Communication.Ports
{
    /// <summary>
    /// 串口奇偶校验位
    /// </summary>
    public enum SerialPortParity
    {
        /// <summary>
        /// 不发生奇偶校验检查
        /// </summary>
        None,

        /// <summary>
        /// 设置奇偶校验位,使位数等于奇数
        /// </summary>
        Odd,

        /// <summary>
        /// 设置奇偶校验位,使位数等于偶数
        /// </summary>
        Even,

        /// <summary>
        /// 将奇偶校验位保留为1
        /// </summary>
        Mark,

        /// <summary>
        /// 将奇偶校验位保留为0
        /// </summary>
        Space
    }

    /// <summary>
    /// 串口停止位数目
    /// </summary>
    public enum SerialPortStopBits
    {
        /// <summary>
        /// 无停止位
        /// </summary>
        None,

        /// <summary>
        /// 1位停止位
        /// </summary>
        One,

        /// <summary>
        /// 2位停止位
        /// </summary>
        Two,

        /// <summary>
        /// 1.5位停止位
        /// </summary>
        OnePointFive
    }

    /// <summary>
    /// 指定在串口上收到字符类型
    /// </summary>
    public enum SerialPortData
    {
        /// <summary>
        /// 接收到一个字符,并将其放入输入缓冲区
        /// </summary>
        Chars = 1,

        /// <summary>
        /// 接收到文件结束符,并将其放入输入缓冲区
        /// </summary>
        Eof
    }

    /// <summary>
    /// 指定在串口上发生的错误
    /// </summary>
    public enum SerialPortError
    {
        /// <summary>
        /// 应用程序尝试传输一个字符,但输出缓冲区已满
        /// </summary>
        TXFull = 0x100,

        /// <summary>
        /// 发生输入缓冲区溢出,输入缓冲区空间不足,或在EOF之后接收到字符
        /// </summary>
        RXOver = 1,

        /// <summary>
        /// 发生字符缓冲区溢出,下一个字符将丢失
        /// </summary>
        Overrun = 2,

        /// <summary>
        /// 硬件检测到奇偶校验错误
        /// </summary>
        RXParity = 4,

        /// <summary>
        /// 硬件检测到一个组帧错误
        /// </summary>
        Frame = 8
    }

    /// <summary>
    /// 指定串口对象上发生更改类型
    /// </summary>
    public enum SerialPortPinChange
    {
        /// <summary>
        /// 信号改变了状态,此信号用于指示能否通过串口发送数据
        /// </summary>
        CtsChanged = 8,

        /// <summary>
        /// 信号改变了状态,此信号用于指示串口上的设备是否已准备运行
        /// </summary>
        DsrChanged = 0x10,

        /// <summary>
        /// 信号改变了状态,此信号用于指示是否调制解调已连接到正常工作的电话线并检测到载波信号
        /// </summary>
        CDChanged = 0x20,

        /// <summary>
        /// 检测到振铃指示
        /// </summary>
        Ring = 0x100,

        /// <summary>
        /// 在输入上检测到一个中断
        /// </summary>
        Break = 0x40
    }

}
